package be.xios.ti.droodle;

import java.awt.*;

/**
 * @author Kris Hermans
 */
public class RectangleShape extends Shape {
	private int x2, y2;

	public RectangleShape(Color color, int x, int y, int x2, int y2, int size,
			boolean filled) {
		super(color, x, y, size, filled);
		this.x2 = x2;
		this.y2 = y2;
	}

	public RectangleShape() {
		super();
		x2 = 0;
		y2 = 0;
	}

	protected void draw(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		int xRect = Math.min(getX(),x2);
		int yRect = Math.min(getY(),y2);
		int width = Math.abs(x2 - getX());
		int height = Math.abs(y2 - getY());
		
		g2d.setColor(getColor());
		g2d.setStroke(new BasicStroke((float) getSize()));
		if (isFilled()) {
			g2d.fillRect(xRect,yRect,width,height);
		} else
			g2d.drawRect(xRect, yRect, width, height);
	}

	/**
	 * @return Returns the x2.
	 */
	public int getX2() {
		return x2;
	}
	/**
	 * @param x2 The x2 to set.
	 */
	public void setX2(int x2) {
		this.x2 = x2;
	}
	/**
	 * @return Returns the y2.
	 */
	public int getY2() {
		return y2;
	}
	/**
	 * @param y2 The y2 to set.
	 */
	public void setY2(int y2) {
		this.y2 = y2;
	}
}